/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TIMELINE_CLIENT_H
#define TIMELINE_CLIENT_H

#include <singleton.h>
#include "itimeline.h"
#include "itimeline_callback.h"
#include "timeline_data_utils.h"
#include "timeline_common.h"
#include "timeline_database_info.h"

namespace OHOS {
namespace Msdp {
class TimelineClient final : public DelayedRefSingleton<TimelineClient> {
    DECLARE_DELAYED_REF_SINGLETON(TimelineClient)

public:
    DISALLOW_COPY_AND_MOVE(TimelineClient);

    void Subscribe(const TimelineDataUtils::TimelineArea& area, const sptr<ITimelineCallback>& callback);
    void UnSubscribe(const TimelineDataUtils::TimelineArea& area, const sptr<ITimelineCallback>& callback);
    bool SetPositionState(int32_t homevalue, int32_t companyvalue);
    bool SetHomePosition(double longitude, double latitude);
    bool SetCompanyPosition(double longitude, double latitude);
    bool SetSleepTime(int32_t sleeptime, int32_t wakeuptime);
    bool SetRestTime(int32_t resttimestart, int32_t resttimeend);
    bool SetWorkTime(int32_t worktimestart, int32_t worktimeend);
    uint32_t GetSleepTime();
    uint32_t GetWakeupTime();
    uint32_t GetRestTimeStart();
    uint32_t GetRestTimeEnd();
    uint32_t GetWorkTimeStart();
    uint32_t GetWorkTimeEnd();
    TimelineDatabaseInfo::ForcecastPosition GetForcecast(uint32_t time = 0);

    
private:
    class TimelineDeathRecipient : public IRemoteObject::DeathRecipient {
    public:
        TimelineDeathRecipient() = default;
        ~TimelineDeathRecipient() = default;
        void OnRemoteDied(const wptr<IRemoteObject>& remote);
    private:
        DISALLOW_COPY_AND_MOVE(TimelineDeathRecipient);
    };

    ErrCode Connect();
    sptr<ITimeline> timelineProxy_ {nullptr};
    sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
    void ResetProxy(const wptr<IRemoteObject>& remote);
    std::mutex mutex_;
};
} // namespace Msdp
} // namespace OHOS
#endif // ITIMELINE_H